﻿using MuddyBoots.GreenlightQC.Mobile.UI.Helpers;
using System;
using System.ComponentModel;
using System.Linq.Expressions;

namespace MuddyBoots.GreenlightQC.Mobile.UI.Model
{
    public abstract class Model
    {
        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        protected void RaisePropertyChanged<T>(Expression<Func<T>> expression)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(ExpressionHelper.Name(expression)));
        }

        protected virtual void SetPropertyAndNotify<T>(ref T currentValue, T newValue, Expression<Func<T>> propertyExpression)
        {
            if (Equals(currentValue, newValue))
            {
                return;
            }

            currentValue = newValue;
            RaisePropertyChanged(propertyExpression);
        }
    }
}
